
****************************************************************************************************
*
* Replication file for: 
*
* Evelyne Hübscher, Thomas Sattler, Markus Wagner. Forthcoming. "Does Austerity Cause Polarization?"
* British Journal of Political Science
*
* Macro Analysis, file 2/2
*
****************************************************************************************************
*
* Date: November 7, 2022
* 
* Software: Stata 17 (Note: coefplot package has to be installed)
*
*
* Figure 1
* --------	

use Data/HSW_BJPS_Macro_Annual.dta, clear

sort year
by year: egen avgwpsd = mean(wpsd)
by year: egen avgabs = mean(abs)
by year: egen avgnms = mean(nms)

sort countryname year
tsset country year

line avgnms year if countryname == "Australia", lpattern(solid) lcolor(black) lwidth(thin) ///
	ytitle("Non-Mainstream Vote", size(4)) ylab(15(5)30, labsize(3.5)) ///
	xtitle("") xlab(1980(5)2015, alt labsize(3.5)) xscale(range(1978 2016)) ///
	legend(off) 
graph export Output/Fig1a.pdf, replace	

line avgabs year if countryname == "Australia", lpattern(solid) lcolor(black) lwidth(thin) ///
	ytitle("Abstention", size(4)) ylab(, labsize(3.5)) ///
	xtitle("") xlab(1980(5)2015, alt labsize(3.5)) xscale(range(1978 2016)) ///
	legend(off) 
graph export Output/Fig1b.pdf, replace		
	
line avgwpsd year if countryname == "Australia", lpattern(solid) lcolor(black) lwidth(thin) ///
	ytitle("Polarization", size(4)) ylab(1.8(0.1)2.2, labsize(3.5)) ///
	xtitle("") xlab(1980(5)2015, alt labsize(3.5)) xscale(range(1978 2016)) ///
	legend(off) 
graph export Output/Fig1c.pdf, replace		
	

* Table 1
* -------

use Data/HSW_BJPS_Macro_Elections.dta, replace

reg dnms lconsol, robust
reg dnms lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
reg dnms lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust

reg dabs lconsol, robust
reg dabs lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
reg dabs lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust

reg dwpsd lconsol, robust
reg dwpsd lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
reg dwpsd lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust


* Figure 2
* --------

reg dwpsd lconsol, robust
sum lconsol
margins, at(lconsol=(0(1)12))

mat pred = r(table)'
svmat pred, names(col)
g consol = (_n-1) 
replace consol = . if consol > 12
g ci_lo = b-1.64*se
g ci_hi = b+1.64*se

sum lconsol if lconsol > 0, det  
local median = r(p50)
local large = r(p50)+r(sd)
local vlarge = r(p50)+2*r(sd)

scatter b consol if consol == 0 | consol == 1 | consol == 2  | consol == 3 | consol == 4 | consol == 5 | ///
		consol == 6 | consol == 7 | consol == 8 | consol == 9 | consol == 10 | consol == 11 | consol == 12, ///
	|| line b consol, lpattern(solid) lcolor(black) lwidth(thin)  ///
	|| rcap ci_lo ci_hi consol if consol == 0 | consol == 1 | consol == 2  | consol == 3 | consol == 4 | consol == 5 | ///
		consol == 6 | consol == 7 | consol == 8 | consol == 9 | consol == 10 | consol == 11 | consol == 12, ///
		msize(vtiny) lpattern(solid) lcolor(black) lwidth(vthin) ///
	|| hist lconsol, bin(24) frac color(grey%25) yaxis(2) ///
	xline(`median') text(0.4 `median' "median" "consoli-" "dation", placement(se) margin(l=1) justification(left)) ///
	xline(`large') text(0.4 `large' "one std." "above" "median", placement(se) margin(l=1) justification(left)) ///
	xline(`vlarge') text(0.4 `vlarge' "two std." "above" "median", placement(se) margin(l=1) justification(left)) ///		
	xlabel(0(2)12, labsize(4.5)) xtitle("Fiscal consolidation", size(5)) ///
	ylabel(, labsize(4.5)) ytitle("{&Delta}Polarization (predicted)", size(5)) ///
	ylabel(, labsize(4.5) axis(2)) ytitle(, size(5) axis(2)) ///
	legend(off) xsize(5.5) scale(0.9) 
graph export Output/Fig2.pdf, replace	

* Table A1
* --------

sum wpsd dwpsd nms dnms abs dabs lconsol ldgrowthm ldunemp ldkofm ldmig lmpgov early3m elecsystem logdismag
	
	
* Table A2
* --------	
	
by country: g elno = _n
tsset country elno

xtunitroot fisher wpsd, pperron lags(1)
xtunitroot fisher dwpsd, pperron lags(1)

xtunitroot fisher nms, pperron lags(1)
xtunitroot fisher dnms, pperron lags(1)

xtunitroot fisher abs, pperron lags(1)
xtunitroot fisher dabs, pperron lags(1)


* Table A3
* --------	
	
reg nms lnms lconsol, robust
reg nms lnms lconsol lgrowthm lunempm lkofm lmig lmpgov early3m i.elecsystem logdismag, robust
reg nms lnms lconsol lgrowthm lunempm lkofm lmig lmpgov early3m i.elecsystem logdismag i.period, robust

reg abs labs lconsol, robust
reg abs labs lconsol lgrowthm lunempm lkofm lmig lmpgov early3m i.elecsystem logdismag, robust
reg abs labs lconsol lgrowthm lunempm lkofm lmig lmpgov early3m i.elecsystem logdismag i.period, robust

reg wpsd lwpsd lconsol, robust
reg wpsd lwpsd lconsol lgrowthm lunempm lkofm lmig lmpgov early3m i.elecsystem logdismag, robust
reg wpsd lwpsd lconsol lgrowthm lunempm lkofm lmig lmpgov early3m i.elecsystem logdismag i.period, robust
	

* Table A4
* --------	
	
reg dleft lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust
reg dnat lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust
reg deco lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust
reg dother lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust
reg dradleft lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust
reg dradright lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period, robust


* Table A5
* --------	

g lspendvstax = lconsol_cuts - lconsol_tax
	
reg dnms c.lconsol##c.lspendvstax ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
reg dabs c.lconsol##c.lspendvstax ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
reg dwpsd c.lconsol##c.lspendvstax ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust


* Table A6
* --------

g fp1_timetoel = elmonth - lfp1_date
g fp2_timetoel = elmonth - lfp2_date
g fp3_timetoel = elmonth - lfp3_date
g fp4_timetoel = elmonth - lfp4_date
g fp5_timetoel = elmonth - lfp5_date

g lfp_1yr = 0
g lfp_2yr = 0
g lfp_3yr = 0
g lfp_4yr = 0

forvalues i = 1/5 {
	replace lfp_1yr = lfp_1yr + lfp_total_`i' if fp`i'_timetoel < 12
}	

forvalues i = 1/5 {
	replace lfp_2yr = lfp_2yr + lfp_total_`i' if fp`i'_timetoel >=12 & fp`i'_timetoel < 24
}	

forvalues i = 1/5 {
	replace lfp_3yr = lfp_3yr + lfp_total_`i' if fp`i'_timetoel >=24 & fp`i'_timetoel < 36
}	

forvalues i = 1/5 {
	replace lfp_4yr = lfp_4yr + lfp_total_`i' if fp`i'_timetoel >=36 & fp`i'_timetoel != .
}	

replace lfp_1yr = 0 if lfp_1yr < 0
replace lfp_2yr = 0 if lfp_2yr < 0
replace lfp_3yr = 0 if lfp_3yr < 0
replace lfp_4yr = 0 if lfp_4yr < 0

reg dnms lfp_1yr lfp_2yr lfp_3yr lfp_4yr ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
test lfp_1yr lfp_2yr lfp_3yr lfp_4yr

reg dabs lfp_1yr lfp_2yr lfp_3yr lfp_4yr ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
test lfp_1yr lfp_2yr lfp_3yr lfp_4yr

reg dwpsd lfp_1yr lfp_2yr lfp_3yr lfp_4yr ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag, robust
test lfp_1yr lfp_2yr lfp_3yr lfp_4yr


* Table A7 and Figure A2
* ----------------------

reg dnms c.lconsol##b1.period ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country, robust
margins, dydx(lconsol) at(period=(1(1)7)) level(90)
mat margins_nms_period= r(table)
mat colnames margins_nms_period = 1980-1984 1985-1989 1990-1994 1995-1999 2000-2004 2005-2009 2010-
coefplot (matrix(margins_nms_period), se(margins_nms_period[2,])), ///
	levels(90) vertical title("Vote for non-mainstream parties", size(4)) ///
	ytitle("Effect of austerity", size(4) height(4)) ylabel(, labsize(4)) ///
	xlabel(, labsize(4) angle(45))  ///
	yline(0) legend(off) scheme(plotplain)
graph export Output/FigA2a.pdf, replace		

reg dabs c.lconsol##b1.period ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country, robust
margins, dydx(lconsol) at(period=(1(1)7)) level(90)
mat margins_abs_period= r(table)
mat colnames margins_abs_period = 1980-1984 1985-1989 1990-1994 1995-1999 2000-2004 2005-2009 2010-
coefplot (matrix(margins_abs_period), se(margins_abs_period[2,])), ///
	levels(90) vertical title("Abstention", size(4)) ///
	ytitle("Effect of austerity", size(4) height(4)) ylabel(, labsize(4)) ///
	xlabel(, labsize(4) angle(45))  ///
	yline(0) legend(off) scheme(plotplain)		
graph export Output/FigA2b.pdf, replace		

reg dwpsd c.lconsol##b1.period ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country, robust
margins, dydx(lconsol) at(period=(1(1)7)) level(90)
mat margins_polar_period= r(table)
mat colnames margins_polar_period = 1980-1984 1985-1989 1990-1994 1995-1999 2000-2004 2005-2009 2010-
coefplot (matrix(margins_polar_period), se(margins_polar_period[2,])), ///
	levels(90) vertical title("Polarization", size(4)) ///
	ytitle("Effect of austerity", size(4) height(4)) ylabel(, labsize(4)) ///
	xlabel(, labsize(4) angle(45))  ///
	yline(0) legend(off) scheme(plotplain)	
graph export Output/FigA2c.pdf, replace		
	

* Figure A4
* ---------
*
* - NMS vote

levelsof countryname, local(country_excl)
mat coefs_nms = J(16, 2, .)
mat colnames coefs_nms = coeff se
mat rownames coefs_nms = `country_excl'

foreach c in `country_excl' {

	reg dnms lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period if countryname != "`c'", robust
	mat results = r(table)
	local pos: list posof "`c'" in local country_excl
	mat coefs_nms[`pos', 1] = results["b", "lconsol"]
	mat coefs_nms[`pos', 2] = results["se", "lconsol"]

}

coefplot (matrix(coefs_nms[,1]), se(coefs_nms[,2])), ///
	levels(90) xline(0) title("Non-mainstream vote", size(5)) ///
	ytitle("Excluded country", size(4)) ylabel(, labsize(3)) ///
	xtitle("Effect of austerity", size(4)) xlabel(, labsize(4)) xsca(range(0 0.03))  ///
	legend(off) scheme(plotplain)
graph export Output/FigA4a.pdf, replace		
	

mat drop results

* - Abstention

levelsof countryname, local(country_excl)
mat coefs_abs = J(16, 2, .)
mat colnames coefs_abs = coeff se
mat rownames coefs_abs = `country_excl'

foreach c in `country_excl' {

	reg dabs lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period if countryname != "`c'", robust
	mat results = r(table)
	local pos: list posof "`c'" in local country_excl
	mat coefs_abs[`pos', 1] = results["b", "lconsol"]
	mat coefs_abs[`pos', 2] = results["se", "lconsol"]

}

coefplot (matrix(coefs_abs[,1]), se(coefs_abs[,2])), ///
	levels(90) xline(0) title("Abstention", size(5)) ///
	ytitle("Excluded country", size(4)) ylabel(, labsize(3)) ///
	xtitle("Effect of austerity", size(4)) xlabel(, labsize(4)) xsca(range(0 0.03))  ///
	legend(off) scheme(plotplain)
graph export Output/FigA4b.pdf, replace		

mat drop results

* - Polarization

levelsof countryname, local(country_excl)
mat coefs_polar = J(16, 2, .)
mat colnames coefs_polar = coeff se
mat rownames coefs_polar = `country_excl'

foreach c in `country_excl' {

	reg dwpsd lconsol ldgrowthm ldunempm ldkofm ldmig lmpgov early3m i.elecsystem logdismag i.country i.period if countryname != "`c'", robust
	mat results = r(table)
	local pos: list posof "`c'" in local country_excl
	mat coefs_polar[`pos', 1] = results["b", "lconsol"]
	mat coefs_polar[`pos', 2] = results["se", "lconsol"]

}

coefplot (matrix(coefs_polar[,1]), se(coefs_polar[,2])), ///
	levels(90) xline(0) title("Polarization", size(5)) ///
	ytitle("Excluded country", size(4)) ylabel(, labsize(3)) ///
	xtitle("Effect of austerity", size(4)) xlabel(, labsize(4)) xsca(range(0 0.03))  ///
	legend(off) scheme(plotplain)
graph export Output/FigA4c.pdf, replace		

mat drop results	



	
	
	




